package cn.cxj.order.service.impl;

import cn.cxj.basic.exception.BusinessException;
import cn.cxj.basic.query.BaseQuery;
import cn.cxj.basic.service.impl.BaseServiceImpl;
import cn.cxj.basic.util.PageList;
import cn.cxj.order.domain.Product;
import cn.cxj.order.domain.ProductDetail;
import cn.cxj.order.mapper.ProductDetailMapper;
import cn.cxj.order.mapper.ProductMapper;
import cn.cxj.order.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl extends BaseServiceImpl<Product> implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private ProductDetailMapper productDetailMapper;
    @Override
    public void add(Product product) {
        if (product == null) {
            throw new BusinessException("参数不能为空!");
        }
        productMapper.save(product);
        ProductDetail productDetail = product.getProductDetail();
        if (productDetail != null) {
            // 商品详情不为空
            productDetail.setProduct_id(product.getId());
            productDetailMapper.save(productDetail);
        }


    }

    @Override
    public Product loadByIdDetail(Long id) {
        return productMapper.loadByIdDetail(id);
    }
}
